//
//  LotteryInformationViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/4/28.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define UISCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
#define UISCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#import "LotteryInformationViewController.h"
//#import "LotteryInformationTableViewCell.h"
#import "LotteryDetailsViewController.h"
#import "UIKit+AFNetworking.h"
#import "ProcurementHallModel.h"
#import "LotteryInformat1TableViewCell.h"
@interface LotteryInformationViewController ()

@end

@implementation LotteryInformationViewController
{
    NSMutableArray *_ProcurementHallArray;
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}
-(void)obtainData
{
    // 启动系统风火轮
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    //服务器给的域名
    NSString *domainStr = @"http://666.lefun6.com/";
    
    //创建一个可变字典
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    //往字典里面添加需要提交的参数
    [parametersDic setObject:@"System" forKey:@"Model"];
    [parametersDic setObject:@"GetSystemConfig" forKey:@"Action"];
    [parametersDic setObject:@"HX_Game_Name" forKey:@"models"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    //以post的形式提交，POST的参数就是上面的域名，parameters的参数是一个字典类型，将上面的字典作为它的参数
    [manager POST:domainStr parameters:parametersDic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 解析成功隐藏系统风火轮
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        
        _ProcurementHallArray = [[NSMutableArray alloc]init];
        
        for (NSDictionary *modeldic in [dic objectForKey:@"HX_Game_Name"]) {
            
            ProcurementHallModel *model = [[ProcurementHallModel alloc]init];
            [model setValuesForKeysWithDictionary:modeldic];
            [_ProcurementHallArray addObject:model];
            
        }
        
        [LotteryInformationtableView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        // 解析失败隐藏系统风火轮(可以打印error.userInfo查看错误信息)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
    }];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self obtainData];
    self.navigationController.navigationBar.translucent = NO;
    UILabel *atitlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
    atitlelabel.text = @"开 奖 信 息";
    atitlelabel.textAlignment = NSTextAlignmentCenter;
    atitlelabel.font = [UIFont boldSystemFontOfSize:17];
    atitlelabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = atitlelabel;
    self.view.backgroundColor = [UIColor yellowColor];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:36/255.0f green:11/255.0f blue:54/255.0f alpha:1];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};

    LotteryInformationtableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT-64) style:UITableViewStylePlain];
    LotteryInformationtableView.dataSource = self;
    LotteryInformationtableView.delegate = self;
    [LotteryInformationtableView registerNib:[UINib nibWithNibName:@"LotteryInformat1TableViewCell" bundle:nil]  forCellReuseIdentifier:@"cell"];
    LotteryInformationtableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:LotteryInformationtableView];
}
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 49;
}
//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _ProcurementHallArray.count;
}

//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdent = @"cell";
    LotteryInformat1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
    
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    ProcurementHallModel *model = [_ProcurementHallArray objectAtIndex:indexPath.row];
    cell.lotteryTitleLabel.text = model.G_N_Title;
    return cell;
}
//单元格点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ProcurementHallModel *model = [_ProcurementHallArray objectAtIndex:indexPath.row];
    LotteryDetailsViewController *lDVC= [[LotteryDetailsViewController alloc] init];
    lDVC.idStr = model.G_N_Id;
    lDVC.name = model.G_N_Title;
    [self.navigationController pushViewController:lDVC animated:YES];
    
}

@end
